package com.money.activemq;
import com.money.domain.Money;
import org.springframework.context.annotation.Configuration;

import javax.jms.*;
import java.io.Serializable;

/**
 *  监听器类：
 * @author
 *
 */
@Configuration
public class Listener implements MessageListener {

    @Override
    public void onMessage(Message message) {
        // 接收Object消息
            if (message instanceof ObjectMessage) {
                ObjectMessage objectMessage = (ObjectMessage) message;
                Serializable serializable = null;
                try {
                    serializable = objectMessage.getObject();
                } catch (JMSException e) {
                    e.printStackTrace();
                }
                Money money = (Money) serializable;
//                Money money = null;
//                try {
//                    money = (Money) objectMessage.getObject();
//                } catch (JMSException e) {
//                    e.printStackTrace();
//                }
                System.out.println("获取 红包消息：  "+money.toString());
            }
            if(message instanceof TextMessage){
                TextMessage textMessage = (TextMessage) message;
                try {
                    System.out.println(textMessage.getText());
                } catch (JMSException e) {
                    e.printStackTrace();
                }
            }
//        TextMessage textMessage = (TextMessage) message;
//        System.out.println(textMessage.toString());
    }
}

